# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               github 1.0
PortGroup               qt5 1.0
PortGroup               cmake 1.1
PortGroup               active_variants 1.1
PortGroup               compiler_blacklist_versions 1.0

github.setup            OpenImageIO oiio 2.1.15.0
revision                0
name                    openimageio
categories              graphics
license                 BSD
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description             a library for reading and writing images
long_description        OpenImageIO is a library for reading and writing images, and a bunch of \
                        related classes, utilities, and applications.
platforms               darwin

checksums               rmd160  753c686d7e6aeb8cf51d807d5acb1d680b895d64 \
                        sha256  95b90ba22b73765cbcbd9e11891769c2e78696ad24d4af77ef3f3c8674422401 \
                        size    29051047

compiler.cxx_standard   2011
# error: multiple overloads of 'address' instantiate to the same signature 'const_pointer (const_reference) const noexcept'
# http://lists.llvm.org/pipermail/llvm-bugs/2013-November/031552.html
# Seen on OSX 10.9 and older.
compiler.blacklist-append {clang < 700}
# error: thread-local storage is not supported for the current target
compiler.blacklist-append {clang < 800}

github.master_sites     ${github.homepage}/archive
distname                Release-${version}
worksrcdir              oiio-Release-${version}

# avoid
#    ccache: error: Failed to create directory ${prefix}/var/macports/build/.ccache/tmp: Operation not permitted
configure.args-append   -DUSE_CCACHE=OFF

# do not "Try to download and build any missing dependencies"
configure.args-append   -DBUILD_MISSING_DEPS=OFF \
                        -DBUILD_MISSING_FMT=OFF

depends_lib-append      port:robin-map \
                        port:zlib \
                        port:bzip2 \
                        port:boost \
                        port:jpeg \
                        port:libpng \
                        port:tiff \
                        port:ilmbase \
                        port:openexr \
                        port:squish \
                        port:libfmt

# optional components

#configure.args-append   -DUSE_OPENGL=OFF \
#                        -DUSE_QT=OFF
qt5.min_version         5.6

configure.args-append   -DUSE_PYTHON=OFF

set pythons_suffixes    {27 36 37 38}

set pythons_ports       {}
foreach s ${pythons_suffixes} {
    lappend pythons_ports python${s}
}

foreach s ${pythons_suffixes} {
    set p python${s}
    set v [string index ${s} 0].[string index ${s} 1]
    set i [lsearch -exact ${pythons_ports} ${p}]
    set c [lreplace ${pythons_ports} ${i} ${i}]
    variant ${p} description "Build the Python ${v} bindings" conflicts {*}${c} "
        depends_build-append    port:pybind11
        depends_lib-append      port:${p} \
                                port:py${s}-numpy

        configure.args-delete   -DUSE_PYTHON=OFF

        configure.args-append   -DPYTHON_VERSION=${v} \
                                -DPYTHON_EXECUTABLE=${prefix}/bin/python${v} \
                                -DPYTHON_SITE_DIR=${frameworks_dir}/Python.framework/Versions/${v}/lib/python${v}
    "
}

set set_python_default  yes
foreach s ${pythons_suffixes} {
    if {[variant_isset python${s}]} {
        set set_python_default  no
    }
}
# this default version should stay synchronized with python_get_default_version
#    in the python PortGroup
if {${set_python_default}} {
    default_variants        +python38
}

#configure.args-append       -DUSE_FIELD3D=OFF
depends_lib-append          port:field3d

#configure.args-append       -DUSE_FFMPEG=OFF
depends_lib-append          port:ffmpeg

# conflicts with jpeg
configure.args-append       -DUSE_JPEGTURBO=OFF
#depends_lib-append          port:libjpeg-turbo

#configure.args-append       -DUSE_OPENJPEG=OFF
depends_lib-append          port:openjpeg

#configure.args-append       -DUSE_OCIO=OFF
depends_lib-append          port:opencolorio

#configure.args-append       -DUSE_OPENCV=OFF
depends_lib-append          port:opencv

#configure.args-append       -DUSE_FREETYPE=OFF
depends_lib-append          port:freetype

#configure.args-append       -DUSE_GIF=OFF
depends_lib-append          port:giflib

#configure.args-append       -DUSE_HEIF=OFF
depends_lib-append          port:libheif

#configure.args-append       -DUSE_PTEX=OFF
depends_lib-append          port:ptex

#configure.args-append       -DUSE_LIBRAW=OFF
depends_lib-append          port:libraw

#configure.args-append       -DUSE_TBB=OFF \
#                            -DUSE_OPENVDB=OFF
depends_lib-append          port:tbb \
                            port:openvdb

# not in MacPorts
configure.args-append       -DUSE_NUKE=OFF

#configure.args-append       -DUSE_DICOM=OFF
depends_lib-append          port:dcmtk

#configure.args-append       -DUSE_WEBP=OFF
depends_lib-append          port:webp

livecheck.regex             archive/Release-(\\d+(?:\\.\\d+)*)${extract.suffix}
